from bs4 import BeautifulSoup
from pool_v2.scrape_killersports import *
from datetime import date, timedelta
from urllib import URLopener

import logging
import traceback


import time

from django.core.management.base import BaseCommand, CommandError

#timezone is currently set to central...
class Command(BaseCommand):
    args = '<hr>'
    help = 'The next time the localtime() hour is equal to arg, a new week will be created'

    def handle(self, *args, **options):
        hour = int(args[0])
        print hour
        opener = URLopener()
        while True:
            if time.localtime().tm_hour == hour:
                d=date.today()
                print d
                cur_time = time.localtime()
                print cur_time
                create_week_from_html(BeautifulSoup(opener.open('http://killersports.com/nba.py/query?sid=guest&text=date%%3D%%3D%i%i%02i&submit=query'  % (cur_time.tm_year,cur_time.tm_mon,cur_time.tm_mday))),d)
                return 0
            time.sleep(900)

